"""
Example job for the process pool
"""
import datetime

from twisted.application.service import IServiceMaker
from twisted.application import internet
from twisted.plugin import IPlugin
from twisted.python import usage
from zope.interface import implements

from fjork import ifjork
from fjork import protocols


class Options(usage.Options):
    optParameters = [["port", "p", 1235, "The port number to listen on."]]


class ExampleJob(object):
    implements(ifjork.IFjork)

    def fjork(self, *args, **kwargs):
        print "ExampleJob: fjorking..."
        print "args:", args
        print "kwargs:", kwargs
        return "<p>How are you today? (%s)</p>"%(datetime.datetime.now(),)


class ExampleJobServiceMaker(object):
    implements(IPlugin, IServiceMaker)
    tapname = "fjorkex"
    description = "An example fjork"
    options = Options

    def makeService(self, options):
        """
        Construct a TCPServer from a factory defined in myproject.
        """
        print "Fjork is ready!"
        return internet.TCPServer(int(options["port"]),
                                  protocols.FjorkClientFactory(ExampleJob))


job = ExampleJobServiceMaker()
